package com.xy.tool.report.excel;

import com.xy.tool.report.view.Table;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zsp on 2018/12/8.
 */
public class MultiWorkbookExcelTemplate extends ExcelTemplate {

    public List<SXSSFWorkbook> create(List<Table> tableList, int[] columnWidthArray) {
        if(CollectionUtils.isEmpty(tableList)) {
            throw new IllegalArgumentException();
        }
        List<SXSSFWorkbook> workbookList = new ArrayList<>();
        for(Table table : tableList) {
            SXSSFWorkbook workbook = new SXSSFWorkbook();
            workbookList.add(workbook);
            createTable(table, columnWidthArray, workbook.createSheet(table.getName()));
        }
        return workbookList;
    }

}
